package Chapter2.Comparing.c3;

public class Practice4 {
    public static void main(String[] args) {
        System.out.println(maxSub("abcwerthelloyuiodef","cvhellobnm"));
    }

    public static String maxSub(String str1, String str2) {
        if(str1.length()<str2.length()){
            String t=str1;
            str1 = str2;
            str2 = t;
        }
        int maxLen=str2.length();
        while(maxLen>0){
            for(int i=0; i+maxLen<str2.length(); i++) {
                String sub= str2.substring(i,i+maxLen);
                if(str1.indexOf(sub)>=0) return sub;
            }
            maxLen--;
        }
        return "";

    }
}
